%!TEX program = xelatex
%!TEX TS-program = xelatex
%!TEX encoding = UTF-8 Unicode

\documentclass[12pt,t,aspectratio=169,mathserif]{beamer}
%Other possible values are: 1610, 149, 54, 43 and 32. By default, it is to 128mm by 96mm(4:3).
%run XeLaTeX to compile.

\input{wang_slides_preamble_windows.tex}

\begin{document}

\title{Complex Analysis}
\subtitle{Chapter 0. cmath - Mathematical functions for complex numbers}
%\institute{SLUC}
\author{\url{https://docs.python.org/3/library/cmath.html}}
%\date
%\renewcommand{\today}{\number\year \,年 \number\month \,月 \number\day \,日}
%\date{ {2023年9月21日} }

\maketitle

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile]{Introduction}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}

\begin{enumerate}%\itemsep1.8cm
\item[1.]  
This module provides access to mathematical functions for complex numbers. 

\item[2.]  
The functions in this module accept integers, floating-point numbers or complex numbers as arguments. 

\item[3.]  
They will also accept any Python object that has either a \verb|__complex__()| or a \verb|__float__()| method: these methods are used to convert the object to a complex or floating-point number, respectively, and the function is then applied to the result of the conversion.


\end{enumerate}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile]{Introduction}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}

\begin{enumerate}%\itemsep1.8cm

\item[4.]  
{\color{blue}For functions involving branch cuts, we have the problem of deciding how to define those functions on the cut itself. }

\item[5.]  
Following Kahan's ``{\it Branch cuts for complex elementary functions}'' paper, as well as Annex G of C99 and later C standards, we use the sign of zero to distinguish one side of the branch cut from the other: 

\begin{center}
\noindent\fbox{%
\parbox{12cm}{%
for a branch cut along (a portion of) the real axis we look at the sign of the imaginary part, while for a branch cut along the imaginary axis we look at the sign of the real part.
}%
}
\end{center}

\end{enumerate}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile]{Introduction}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}

\begin{enumerate}%\itemsep1.8cm

\item[7.]  
For example, the \verb|cmath.sqrt()| function has a branch cut along the negative real axis. 

\item[8.]  
An argument of \verb|complex(-2.0, -0.0)| is treated as though it lies below the branch cut, and so gives a result on the negative imaginary axis:

\begin{python}
cm.sqrt(complex(-2.0, -0.0))
-1.4142135623730951j
\end{python}

\item[9.]  
But an argument of \verb|complex(-2.0, 0.0)| is treated as though it lies above the branch cut:

\begin{python}
cm.sqrt(complex(-2.0, 0.0))
1.4142135623730951j
\end{python}

\end{enumerate}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile]{Conversions to and from polar coordinates}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}

\begin{enumerate}%\itemsep1.8cm
\item[1.]  
A Python complex number \verb|z| is stored internally using rectangular or Cartesian coordinates. 

\item[2.]  
It is completely determined by its {\color{blue}real part} \verb|z.real| and its {\color{blue}imaginary part} \verb|z.imag|.

\item[3.]  
Polar coordinates give an alternative way to represent a complex number. 

\item[4.]  
In polar coordinates, a complex number \verb|z| is defined by the {\color{blue}modulus} \verb|r| and the {\color{blue}phase angle} \verb|phi|. 

\item[5.]  
The modulus \verb|r| is the distance from \verb|z| to the origin, while the phase \verb|phi| is the counterclockwise angle, measured in radians, from the positive x-axis to the line segment that joins the origin to \verb|z|.

\end{enumerate}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile]{Conversions to and from polar coordinates}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}

\begin{enumerate}%\itemsep1.8cm

\item[6.]  
The following functions can be used to convert from the native rectangular coordinates to polar coordinates and back.

\item[7.]  
{\color{red}\verb|cmath.phase(x)|} \\
Return the phase of \verb|x| (also known as the {\color{blue}argument} of \verb|x|), as a float.

\item[8.]  
\verb|phase(x)| is equivalent to \verb|math.atan2(x.imag, x.real)|. 

\item[9.]  
The result lies in the range $[-\pi, \pi]$, and the branch cut for this operation lies along the negative real axis. 


\end{enumerate}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile]{Conversions to and from polar coordinates}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}

\begin{enumerate}%\itemsep1.8cm

\item[10.]  
The sign of the result is the same as the sign of \verb|x.imag|, even when \verb|x.imag| is zero:

\begin{python}
phase(complex(-1.0, 0.0))
3.141592653589793
phase(complex(-1.0, -0.0))
-3.141592653589793
\end{python}

\item[11.]  
Note The {\color{blue}modulus (absolute value)} of a complex number \verb|x| can be computed using the built-in \verb|abs()| function. 

\item[12.]  
There is no separate \verb|cmath| module function for this operation.


\end{enumerate}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile]{Conversions to and from polar coordinates}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}

\begin{enumerate}%\itemsep1.8cm

\item[13.]  
{\color{red}\verb|cmath.polar(x)|} 
\begin{itemize}
\item  Return the representation of \verb|x| in polar coordinates. 
\item  Returns a pair \verb|(r, phi)| where \verb|r| is the modulus of \verb|x| and \verb|phi| is the phase of \verb|x|. 
\item  \verb|polar(x)| is equivalent to \verb|(abs(x), phase(x))|.
\end{itemize}


\item[14.]  
{\color{red}\verb|cmath.rect(r, phi)|} 
\begin{itemize}
\item  Return the complex number \verb|x| with polar coordinates \verb|r| and \verb|phi|. 
\item  Equivalent to \verb|complex(r * math.cos(phi), r * math.sin(phi))|.
\end{itemize}


\end{enumerate}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile]{Power and logarithmic functions}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}

\begin{enumerate}%\itemsep1.8cm
\item[1.]  
{\color{red}\verb|cmath.exp(x)|} 
\begin{itemize}
\item  Return $e$ raised to the power $x$, where $e$ is the base of natural logarithms.
\end{itemize}

\item[2.]  
{\color{red}\verb|cmath.log(x[, base])|}  
\begin{itemize}
\item  Returns the logarithm of $x$ to the given base. 
\item  If the base is not specified, returns the natural logarithm of $x$. 
\item  {\color{blue}There is one branch cut, from 0 along the negative real axis to $-\infty$.}
\end{itemize}

\item[3.]  
{\color{red}\verb|cmath.log10(x)|} 
\begin{itemize}
\item  Return the base-10 logarithm of $x$. 
\item  This has the same branch cut as \verb|log()|.
\end{itemize}

\item[4.]  
{\color{red}\verb|cmath.sqrt(x)|} 
\begin{itemize}
\item  Return the square root of $x$. 
\item  This has the same branch cut as \verb|log()|.
\end{itemize}

\end{enumerate}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile]{Trigonometric functions}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}

\begin{enumerate}%\itemsep1.8cm
\item[1.]  
{\color{red}\verb|cmath.acos(x)|}  
\begin{itemize}
\item  Return the arc cosine of $x$. 
\item  {\color{blue}There are two branch cuts: One extends right from 1 along the real axis to $\infty$. The other extends left from $-1$ along the real axis to $-\infty$. }
\end{itemize}

\item[2.]  
{\color{red}\verb|cmath.asin(x)|}  
\begin{itemize}
\item  Return the arc sine of $x$. 
\item  This has the same branch cuts as \verb|acos()|.
\end{itemize}

\item[3.]  
{\color{red}\verb|cmath.atan(x)|}  
\begin{itemize}
\item  Return the arc tangent of $x$. 
\item  {\color{blue}There are two branch cuts: One extends from $1j$ along the imaginary axis to $\infty j$. The other extends from $-1j$ along the imaginary axis to $-\infty j$. }
\end{itemize}

\end{enumerate}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile]{Trigonometric functions}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}

\begin{enumerate}%\itemsep1.8cm
\item[4.]  
{\color{red}\verb|cmath.cos(x)|}   
\begin{itemize}
\item  Return the cosine of $x$.
\end{itemize}

\item[5.]  
{\color{red}\verb|cmath.sin(x)|}  
\begin{itemize}
\item  Return the sine of $x$.
\end{itemize}

\item[6.]  
{\color{red}\verb|cmath.tan(x)|}  
\begin{itemize}
\item  Return the tangent of $x$.
\end{itemize}

\end{enumerate}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile]{Hyperbolic functions}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}

\begin{enumerate}%\itemsep1.8cm
\item[1.]  
{\color{red}\verb|cmath.acosh(x)|}  
\begin{itemize}
\item  Return the inverse hyperbolic cosine of $x$. 
\item  There is one branch cut, extending left from 1 along the real axis to $-\infty$.
\end{itemize}

\item[2.]  
{\color{red}\verb|cmath.asinh(x)|}   
\begin{itemize}
\item  Return the inverse hyperbolic sine of $x$. 
\item  There are two branch cuts: One extends from $1j$ along the imaginary axis to $\infty j$. The other extends from $-1j$ along the imaginary axis to $-\infty j$.
\end{itemize}

\item[3.]  
{\color{red}\verb|cmath.atanh(x)|}   
\begin{itemize}
\item  Return the inverse hyperbolic tangent of $x$. 
\item  There are two branch cuts: One extends from $1$ along the real axis to $\infty$. The other extends from $-1$ along the real axis to $-\infty$.
\end{itemize}


\end{enumerate}


\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile]{Hyperbolic functions}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}

\begin{enumerate}%\itemsep1.8cm
\item[4.]  
{\color{red}\verb|cmath.cosh(x)|}   
\begin{itemize}
\item  Return the hyperbolic cosine of $x$.
\end{itemize}

\item[5.]  
{\color{red}\verb|cmath.sinh(x)|}  
\begin{itemize}
\item  Return the hyperbolic sine of $x$.
\end{itemize}

\item[6.]  
{\color{red}\verb|cmath.tanh(x)|}  
\begin{itemize}
\item  Return the hyperbolic tangent of $x$.
\end{itemize}

\end{enumerate}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile]{Classification functions}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}

\begin{enumerate}%\itemsep1.8cm
\item[1.]  
{\color{red}\verb|cmath.isfinite(x)| }  
\begin{itemize}
\item  Return True if both the real and imaginary parts of x are finite, and False otherwise.
\end{itemize}
%Added in version 3.2.

\item[2.]  
{\color{red}\verb|cmath.isinf(x)| }  
\begin{itemize}
\item  Return True if either the real or the imaginary part of x is an infinity, and False otherwise.
\end{itemize}

\item[3.]  
{\color{red}\verb|cmath.isnan(x)| } 
\begin{itemize}
\item  Return True if either the real or the imaginary part of x is a NaN, and False otherwise.
\end{itemize}

\item[4.]  
{\color{red}\verb|cmath.isclose(a, b, *, rel_tol=1e-09, abs_tol=0.0)| }
\begin{itemize}
\item  Return True if the values a and b are close to each other and False otherwise.
\end{itemize}

\end{enumerate}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile]{Classification functions}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}

\begin{enumerate}%\itemsep1.8cm
\item[1.]  
Whether or not two values are considered close is determined according to given absolute and relative tolerances.

\item[2.]  
\verb|rel_tol| is the {\color{blue}relative tolerance} - it is the maximum allowed difference between $a$ and $b$, relative to the larger absolute value of $a$ or $b$. 

\item[3.]  
For example, to set a tolerance of 5\%, pass \verb|rel_tol=0.05|. 

\item[4.]  
The default tolerance is \verb|1e-09|, which assures that the two values are the same within about 9 decimal digits. \verb|rel_tol| must be greater than zero.

\end{enumerate}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile]{Classification functions}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}

\begin{enumerate}%\itemsep1.8cm

\item[5.]  
\verb|abs_tol| is the {\color{blue}minimum absolute tolerance} - useful for comparisons near zero. \verb|abs_tol| must be at least zero.

\item[6.]  
If no errors occur, the result will be: 
\verb|abs(a-b) <= max(rel_tol * max(abs(a), abs(b)), abs_tol)|.

\item[7.]  
The IEEE 754 special values of \verb|NaN|, \verb|inf|, and \verb|-inf| will be handled according to IEEE rules. 

\item[8.]  
Specifically, \verb|NaN| is not considered close to any other value, including \verb|NaN|. 

\item[9.]  
\verb|inf| and \verb|-inf| are only considered close to themselves.

\end{enumerate}

\end{frame}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile]{Constants}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}

\begin{enumerate}%\itemsep1.8cm

\item[1.]
{\color{red}\verb|cmath.pi|}  
\begin{itemize}
\item  The mathematical constant $\pi$, as a float.
\end{itemize}

\item[2.]
{\color{red}\verb|cmath.e|}  
\begin{itemize}
\item  The mathematical constant $e$, as a float.
\end{itemize}

\item[3.]
{\color{red}\verb|cmath.tau|}  
\begin{itemize}
\item  The mathematical constant $\tau$, as a float.
%Added in version 3.6.
\end{itemize}

\item[4.]
{\color{red}\verb|cmath.inf|}  
\begin{itemize}
\item  Floating-point positive infinity. Equivalent to float('inf').
%Added in version 3.6.
\end{itemize}

\item[5.]
{\color{red}\verb|cmath.infj|}  
\begin{itemize}
\item  Complex number with zero real part and positive infinity imaginary part. 
\item  Equivalent to \verb|complex(0.0, float('inf'))|.
%Added in version 3.6.
\end{itemize}

\end{enumerate}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile]{Constants}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}

\begin{enumerate}%\itemsep1.8cm

\item[6.]
{\color{red}\verb|cmath.nan|}  
\begin{itemize}
\item  A floating-point ``not a number'' (NaN) value. 
\item  Equivalent to \verb|float('nan')|.
%Added in version 3.6.
\end{itemize}

\item[7.]
{\color{red}\verb|cmath.nanj|}  
\begin{itemize}
\item  Complex number with zero real part and NaN imaginary part. 
\item  Equivalent to \verb|complex(0.0, float('nan'))|.
\end{itemize}

\end{enumerate}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile]{Notes}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}

\begin{enumerate}%\itemsep1.8cm
\item[1.]  
Note that the selection of functions is similar, but not identical, to that in module \verb|math|. 

\item[2.]  
The reason for having two modules is that some users aren't interested in complex numbers, and perhaps don't even know what they are. 

\item[3.]  
They would rather have \verb|math.sqrt(-1)| raise an exception than  return a complex number. 

\item[4.]  
Also note that the functions defined in \verb|cmath| always return a complex number, even if the answer can be expressed as a real number (in which case the complex number has an imaginary part of zero).

\item[5.]  
A note on branch cuts: They are curves along which the given function fails to be continuous. 

\end{enumerate}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile]{Notes}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}

\begin{enumerate}%\itemsep1.8cm

\item[6.]  
They are a necessary feature of many complex functions. 

\item[7.]  
It is assumed that if you need to compute with complex functions, you will understand about branch cuts. 

\item[8.]  
Consult almost any (not too elementary) book on complex variables for enlightenment. 

\item[9.]  
For information of the proper choice of branch cuts for numerical purposes, a good reference should be the following:
\begin{itemize}
\item 
Kahan, W., Branch cuts for complex elementary functions; 
\end{itemize}

\item[10.]  
or, Much ado about nothing's sign bit. In 
\begin{itemize}
\item 
Iserles, A., and Powell, M. (eds.), The state of the art in numerical analysis. Clarendon Press (1987) pp.165–211.
\end{itemize}

\end{enumerate}

\end{frame}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\end{document}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
